-
Notifications
You must be signed in to change notification settings - Fork 92
gpep-passthrough-consent-field.php: Added snippet for easy passthrough on Consent Field.
#1078
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ugh on Consent Field.
WalkthroughA new PHP snippet has been added to enable automatic passthrough of a consent field value between two Gravity Forms using the Gravity Perks Easy Passthrough add-on. The code hooks into the form rendering process, checks for a valid passthrough token, retrieves the relevant entry data, and, if consent was previously given, injects JavaScript to pre-check the consent checkbox on the target form before it is displayed to the user. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant GravityForms
participant PHP Snippet
participant EasyPassthrough
participant Browser
User->>GravityForms: Accesses target form (with ep_token)
GravityForms->>PHP Snippet: Triggers gform_pre_render filter
PHP Snippet->>EasyPassthrough: Checks token, retrieves entry data
EasyPassthrough-->>PHP Snippet: Returns entry data (consent value)
PHP Snippet->>PHP Snippet: Checks if consent was given
alt Consent given
PHP Snippet->>GravityForms: Injects JS to pre-check consent checkbox
end
GravityForms-->>Browser: Renders modified form
Browser->>Browser: JS checks consent checkbox on DOMContentLoaded
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (5)
gp-easy-passthrough/gpep-passthrough-consent-field.php (5)
11-14: Consider making configuration values more flexible.Currently, the field IDs and form ID are hardcoded and require manual editing. Consider enhancing this with:
- Constants that can be defined elsewhere
- A settings page interface
- Function parameters for programmatic configuration
This would make the snippet more maintainable and easier to reuse across multiple forms.
16-18: Use strict comparison for form ID check.Replace loose comparison with strict comparison to prevent potential type juggling issues.
- if ( $form['id'] != $target_form_id ) { + if ( $form['id'] !== $target_form_id ) {
26-34: Consider using WordPress enqueue method for JavaScript.Instead of directly outputting JavaScript in the PHP, consider using WordPress' proper script enqueuing methods. This provides better compatibility with caching plugins and follows WordPress best practices.
- ?> - <script type="text/javascript"> - document.addEventListener( 'DOMContentLoaded', function() { - var consentCheckbox = document.querySelector( 'input[name="input_<?php echo $field->id; ?>.1"] '); - - if ( consentCheckbox ) { - consentCheckbox.checked = true; - } - }); - </script> - <?php + add_action( 'wp_footer', function() use ( $field ) { + ?> + <script type="text/javascript"> + document.addEventListener( 'DOMContentLoaded', function() { + var consentCheckbox = document.querySelector( 'input[name="input_<?php echo $field->id; ?>.1"] '); + + if ( consentCheckbox ) { + consentCheckbox.checked = true; + } + }); + </script> + <?php + } );
28-28: Fix spacing issue in JavaScript selector.There's an extra space at the end of the selector string which could potentially cause issues in some browsers.
- var consentCheckbox = document.querySelector( 'input[name="input_<?php echo $field->id; ?>.1"] '); + var consentCheckbox = document.querySelector( 'input[name="input_<?php echo $field->id; ?>.1"]' );
1-41: Consider future extensibility for multiple consent fields.The current implementation works well for a single consent field mapping, but consider future extensibility for mapping multiple consent fields. A configuration array approach would make this more flexible:
$consent_field_mappings = array( array( 'source_id' => '4', 'target_id' => '4', 'target_form_id' => '80' ), // Additional mappings can be added here );This would allow for easier expansion when needed.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
gp-easy-passthrough/gpep-passthrough-consent-field.php(1 hunks)
🔇 Additional comments (1)
gp-easy-passthrough/gpep-passthrough-consent-field.php (1)
1-9: Well-documented header section.The header clearly explains the purpose of the snippet and includes useful links to documentation and an instruction video. This makes it easy for developers to understand and implement.
veryspry
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@saifsultanc sorry for the double review, I just noticed a potential issue with the JS query selector.
…ugh on Consent Field.
Context
⛑️ Ticket(s): https://secure.helpscout.net/conversation/2906273408/82137
Summary
Added support for passthrough with Consent field, which is delisted from mapping on GPEP here: https://github.com/gravitywiz/gp-easy-passthrough/pull/62
How this snippet works:
https://www.loom.com/share/209126dc84ab483b9025c040f5adf450